<template>
  <div style="height: 100%;overflow: hidden;" >
    <div class="login-left">
      <div class="logo" style="left: 48px;top: 55.85px;width: 152px;height: 26.93px;"></div>
      <div class="decoration" style="width:276px;height:176px"></div>
      <div class="decoration1" style="width:310px;height:310px"></div>
      <div class="login-left-image" :style="bgStyle">
      </div>
    </div>
    <div class="login-container">
      <div class="login-div">
        <el-form
          ref="loginForm"
          v-if="loginType === 'pc'"
          :model="loginForm"
          :rules="loginRules"
          class="login-form"
          autocomplete="on"
          :hide-required-asterisk="true"
          label-position="top"
          label-width="80px"
          @keydown.enter.native="handleLogin"
          size="normal"
        >
          <div class="title-container">
            <div class="title bold" style="letter-spacing:0px">玄通</div>
          </div>

          <el-form-item prop="userName">
            <div class="c-label">用户名</div>
            <el-input
              ref="username"
              v-model="loginForm.userName"
              placeholder="请输入用户名"
              name="username"
              type="text"
              tabindex="1"
              autocomplete="on"
              prefix-icon="el-icon-user"
            />
          </el-form-item>
          <el-form-item prop="password">
            <div class="c-label">密码</div>
            <el-input
              ref="password"
              v-model="loginForm.password"
              type="password"
              placeholder="请输入密码"
              name="password"
              tabindex="2"
              autocomplete="on"
              prefix-icon="el-icon-unlock"
            />
          </el-form-item>
          <el-form-item prop="verify">
            <div class="c-label">验证码</div>
            <el-input
              ref="verify"
              v-model="loginForm.verify"
              name="verify"
              tabindex="3"
              placeholder="请输入验证码"
              autocomplete="off"
              style="width: 56%"
              prefix-icon="el-icon-unlock"
            />
            <img
              class="verify-code"
              :src="verifyImg"
              alt=""
              @click="getVerifyImg"
            />
          </el-form-item>

          <el-form-item>
            <el-button
              :loading="loading"
              type="primary"
              style="width: 100%; margin-top: 10px"
              @click.native.prevent="handleLogin"
              >登录
            </el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- <div
        style="
          position: absolute;
          bottom: 0;
          width: 100%;
          height: 60px;
          line-height: 60px;
          background-color: #e3e8e9;
          display: flex;
          justify-content: center;
          font-size: 12px;
        "
      >
        <!-- © 2023 Inspur 使用浪潮媒资搜索引擎必读 浪潮版权声明 -->
        {{copyright}}
      </div> -->
    </div>
  </div>
</template>

<script>
import { verifyImg } from '@/api/login-base';
export default {
  name: 'Login',
  data() {
    return {
      loginMap: null,
      loginType: 'pc',
      filePath: filePath,
      codeStatus: 2,
      loginForm: {
        userName: '',
        password: '',
        verify: '',
        checkToken: '' //验证码验证用token
      },
      loginRules: {
        userName: [
          { required: true, trigger: 'blur', message: '请输入用户名' }
        ],
        password: [{ required: true, trigger: 'blur', message: '请输入密码' }],
        verify: [{ required: true, trigger: 'blur', message: '请输入验证码' }]
      },
      verifyImg: '',

      loading: false,
      redirect: undefined,
      otherQuery: {},
      title: this.$store.state.settings.title,
      codeObj: null,
      timeout: null,
      bgStyle: {},
      copyright: ''
    };
  },
  watch: {},
  created() {
    this.getVerifyImg();
  },
  mounted() {},
  destroyed() {},
  methods: {
    /**
     * 获取验证码图片
     */
    getVerifyImg() {
      verifyImg().then(res => {
        this.verifyImg = res.base64Img;
        this.loginForm.checkToken = res.checkToken;
        this.loginForm.verify = '';
      });
    },
    handleLogin() {
      this.$refs.loginForm.validate(valid => {
        if (valid) {
          this.loading = true;
          this.$store
            .dispatch('user/login', this.loginForm)
            .then(() => {
              this.$router.push({
                path: this.redirect || '/',
                query: this.otherQuery
              });
              this.loading = false;
            })
            .catch(() => {
              this.loading = false;
              this.getVerifyImg();
            });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.login-left {
  float: left;
  height: 100%;
  width: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  .logo {
    position: absolute;
    background: url('~@/assets/logo.png') no-repeat;
  }
  .decoration1 {
    position: absolute;
    background: url('~@/assets/decoration.png') no-repeat;
    bottom: 0;
    right: 0;
    background-position: right bottom;
  }
  .decoration {
    position: absolute;
    background: url('~@/assets/decoration.png') no-repeat;
    top: 0;
    left: 100%;
  }
  .login-left-image {
    width: 100%;
    height: 100%;
    background: url('~@/assets/BG.png') no-repeat;
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;

    span {
      margin-bottom: 9%;
      color: white;
      font-size: 20px;
      font-weight: 500;
      line-height: 17px;
      letter-spacing: 2px;
    }
  }
}

.login-container {
  overflow: hidden;
  height: 100%;
  // background: url('~@/assets/login_bg.png') no-repeat;
  // background-size: cover;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  .logo-title {
    height: 27px;
    position: absolute;
    top: 42px;
    right: 40px;
    display: flex;
    align-items: flex-end;
    .logo-image {
      height: 23px;
      margin-right: 16px;
    }
    .sys-title {
      height: 100%;
      font-size: 20px;
      font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
      font-weight: bold;
      color: #202228;
      letter-spacing: 1px;
    }
  }
  .login-div {
    // width: 539px;
    // height: 485px;
    // background: #ffffff;
    // box-shadow: 0px 2px 7px 0px rgba(0, 0, 0, 0.1);
    // border-radius: 6px;
    // border: 1px solid #dddddd;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    .img-div {
      position: absolute;
      top: 0;
      right: 0;
      width: 83px;
      height: 74px;
      img {
        width: 100%;
        height: 100%;
        cursor: pointer;
      }
    }
  }
  .code-login {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .title {
      font-size: 24px;
      letter-spacing: 5px;
      font-family: MicrosoftYaHeiSemibold;
      color: #2f2f2f;
      line-height: 32px;
      margin-bottom: 50px;
      text-align: center;
    }
    .code-div {
      padding: 20px;
      width: 219px;
      height: 219px;
      // background: #ffffff;
      border-radius: 6px;
      border: 1px solid #e8e8e8;

      .code-img {
        width: 100%;
        height: 100%;
      }
      .code-tip {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        .tip-info {
          font-size: 14px;
          font-family: MicrosoftYaHei;
          color: #ffffff;
          line-height: 19px;
        }
      }
    }
    .tip {
      font-size: 14px;
      font-family: MicrosoftYaHei;
      color: #2f2f2f;
      line-height: 19px;
      margin-top: 29px;
      text-align: center;
    }
  }
}

.login-form {
  width: 400px;
  // margin: 20px auto 100px;

  .title {
    margin-bottom: 30px;
    letter-spacing: 5px;
    font-size: 24px;
    font-family: MicrosoftYaHeiSemibold;
    color: #333333;
  }

  .verify-code {
    height: 40px;
    width: 40%;
    float: right;
    border-radius: 4px;
  }
}
.bgBlack {
  background: rgba(0, 0, 0, 0.74);
}
.pointer {
  cursor: pointer;
}

::v-deep.el-button--primary {
  background: #0d48ce;
  border-color: #0d48ce;
  color: #fff;
}

::v-deep.el-button--primary:hover {
  background: #0d48ce;
  border-color: #0d48ce;
  color: #fff;
}
</style>
